<?
include_once(INCLUDES."config.php");
include_once(INCLUDES."xoadau.php");
function buildlink($type,$post,$page="",$fulllink=1)
{
	global $config;
	if($type=="menu")
	{
		if($post['code']!="bai-thi")
		{
			if($page=="")
				$link= "/$post[code].html";
			else
				$link= "/$post[code]/trang-$page.html";
		}
		else
		{ //menu bài thi
			$post["year"]=$config["year"];
			if($post["round"]=="")
			{
				$q=query("select * from round where status='1';");
				if(numrows($q)==0) $q=query("select * from round limit 1;");
				$r=fetch($q);
				$post["round"]=$r["code"];
			}
			if($page=="")
				$link= "/bai-thi/$post[round]/nam-$post[year].html";
			else
				$link= "/bai-thi/$post[round]/nam-$post[year]/trang-$page.html";
		}
	}
	elseif($type=="baithi")
	{
		$post["year"]=$config["year"];
			if($post["round"]=="")
			{
				$q=query("select * from round where status='1';");
				if(numrows($q)==0) $q=query("select * from round limit 1;");
				$r=fetch($q);
				$post["round"]=$r["code"];
			}
			if($page=="")
				$link= "/bai-thi/$post[round]/nam-$post[year].html";
			else
				$link= "/bai-thi/$post[round]/nam-$post[year]/trang-$page.html";
	}
	elseif($type=="ngoi-sao-toc-viet")
	{
			
				$link= "/ngoi-sao-toc-viet/".xoadau($post["hoten"])."-".$post["id"].".html";
	}
	elseif($type=="xembaithi")
	{
		$q=query("select * from round where code ='$post[round]'");
		$r=fetch($q);
		$link= "/xem-bai-thi/".xoadau($post["name"])."-$r[roundname]-nam-$post[year]-$post[id].html";
	}
	elseif($type=="post")
	{
		$q=query("select code from menu where id=$post[parent]");
		if(numrows($q)==0) goto ERROR;
		$r=fetch($q);
		$link= "/$r[code]/".xoadau($post["title"])."-$post[id].html";
	}
	elseif($type=="hinhanh")
	{
		$q=query("select id from gallery_album where id=$post[id]");
		if(numrows($q)==0) goto ERROR;
		$r=fetch($q);
		$link= "/hinh-anh/".xoadau($post["name"])."-$post[id].html";
	}
	elseif($type=="tags")
	{
		if($page=="")
				$link= "/tags/$post[code].html";
			else
				$link= "/tags/$post[code]/trang-$page.html";
	}
$dirname=str_replace("\\","/",dirname(__DIR__));
if($fulllink==1)
	return BASELINK.$link;
return ".".$link;
ERROR:
return "./error.html";
}
/*
#ngochip.net/bai-thi/vong-1/nam-2015.html
RewriteRule ^bai-thi/vong-([0-9]*)/nam-([0-9]*).html index.php?act=baithi&term=$1&year=$2
#ngochip.net/bai-thi/vong-1/nam-2015/trang-3.html
RewriteRule ^bai-thi/vong-([0-9]*)/nam-([0-9]*)/trang-([0-9]*).html index.php?act=baithi&term=$1&year=$2&page=$3
#ngochip.net/xem-bai-thi/nam-tay-nhau-2314.html
RewriteRule ^xem-bai-thi/([0-9A-Za-z-]*)-([0-9]*).html index.php?act=chitietbaithi&id=$2

#ngochip.net/gioi-thieu.html
RewriteRule ^([0-9A-Za-z-]*).html index.php?act=menu&code=$1
#ngochip.net/tin-tuc/trang-2.html
RewriteRule ^([0-9A-Za-z-]*)/trang-([0-9]*).html index.php?act=menu&code=$1&page=$2

#ngochip.net/tin-tuc/hom-nay-la-mot-ngay-dep-troi.html
RewriteRule ^([0-9A-Za-z-]*)/([0-9A-Za-z-]*)-([0-9]*).html index.php?act=post&id=$3


*/
?>